/**
 * 去除html标签
 * @param {*} data 
 */
const fnhtmlString=data=>{
    let dd = data.replace(/<\/?.+?>/g, "");
    let dds = dd.replace(/ /g, ""); //dds为得到后的内容
    let ddds=dds.replace(/&nbsp;/g,"");
    return ddds;
}
/**
 * 从html标签中提取图片
 * @param {*} data 
 */
const fnextractDataImage=data=>{
    let reg = /<img.+?src=('|")?([^'"]+)('|")?(?:\s+|>)/gim;
    let arr = [];
    let tem;
    while(tem = reg.exec(data)) {
        arr.push(tem[2]);
    }
    return arr;
}
/**
 * 字符串截取
 * @param {*} val 
 * @param {*} num 
 */
const fninterceptString=(val,num)=>{
    let count = val.length;
    let data = val;
    if(count > num) {
        data = val.substring(0, num) + '...';
    }
    return data;
}
/**
 * 时间格式化
 * @param {*} time 
 */
const fnDatetime=time=>{
    let obj=new Object();
    if(time != null||time!='') {
        let date = new Date(time);
        let y = date.getFullYear();
        let M = date.getMonth() + 1;
        let d = date.getDate();
        let h = date.getHours();
        let m = date.getMinutes();
        let s = date.getSeconds(); //获取秒

        if(M < 10) {
            M = '0' + M;
        }
        if(d < 10) {
            d = '0' + d;
        }
        if(h < 10) {
            h = '0' + h;
        }
        if(m < 10) {
            m = '0' + m;
        }
        if(s < 10) {
            s = '0' + s;
        }
        obj.year=y;
        obj.month=M;
        obj.day=d;
        obj.hours=h;
        obj.minutes=m;
        obj.seconds=s;
    } else {
        obj=null;
    }
    return obj;
}

export{
    fnhtmlString,
    fnextractDataImage,
    fninterceptString,
    fnDatetime
}